package com.haruhinav.controller.admin;

import com.haruhinav.entity.Address;
import com.haruhinav.entity.AddressType;
import com.haruhinav.entity.extend.AddressEX;
import com.haruhinav.entity.vo.ResultVO;
import com.haruhinav.service.AddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/address")
public class AdminAddressController {
    @Resource
    private AddressService addressService;



    //    所有地址 一对一
    @PostMapping(value = "/y/list")
    public ResultVO getAllAddress(@RequestBody AddressEX addressEX){

        return addressService.getAllAddress(addressEX);
    }
    // 修改地址状态 flag
    @PostMapping("/y/update/state")
    public ResultVO updateAddressState(@RequestBody Address address){
        return addressService.updateState(address.getFlag(),address.getId());
    }
    //添加地址
    @PostMapping("/y/insert")
    public ResultVO addNavAddress(@RequestBody Address address){
        return addressService.addNavAddress(address);
    }
    //根据id查找地址
    @GetMapping("/y/one")
    public Address findAddressById(@RequestParam("id") Integer id){
        return addressService.findAddressById(id);
    }
    //    更新地址所有字段
    @PostMapping("/y/update/all")
    public ResultVO updateAddress(@RequestBody Address address){
        return addressService.updateAddress(address);
    }

    //    删除地址 by id
    @PostMapping("/y/delete")
    public ResultVO removeAddressById(@RequestBody Address address){
        return addressService.removeAddressById(address.getId());
    }
//   返回所有地址类型
    @GetMapping("/y/type/list")
    public List<AddressType> queryAllAddressType(){
        return addressService.queryAllAddressType(new AddressType());
    }
    //所有地址类型 以及查询
    @GetMapping("/y/type/list/by")
    public List<AddressType> addressTypes(@RequestParam("n") String name, @RequestParam("l") String label){
        AddressType type = new AddressType();
        type.setName(name);
        type.setLabel(label);
        return addressService.queryAllAddressType(type);
    }

// 添加地址类型
    @PostMapping("/y/type/insert")
    public ResultVO insertAddressType(@RequestBody AddressType addressType){
        return addressService.insertAddressType(addressType);
    }

//    修改地址类型颜色

    @PostMapping("/y/type/update/color")
    //@RequestBody AddressType addressType,String mark
    public ResultVO updateAddressTypeColorV2(@RequestBody Map repMap){

        return addressService.updateAddressTypeColor(repMap, repMap.get("mark").toString());
    }
//  删除地址类型
    @PostMapping("/y/type/delete")
    public ResultVO removeAddressTypeById(@RequestBody AddressType addressType){
        return addressService.removeAddressTypeById(addressType);
    }

//修改地址类型
    @PostMapping("/y/type/update")
    public ResultVO updateAddressType(@RequestBody AddressType addressType){
        return addressService.updateAddressType(addressType);
    }
//    根据id查询地址类型
    @GetMapping("/y/type/one")
    public AddressType findAddressTypeById(@RequestParam("tid") int id){
        return addressService.findAddressTypeById(id);
    }

}
